package Gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;

import javax.swing.JOptionPane;

import domein.server.IBuilder;

public class TextFieldHandler implements ActionListener 
{
	private int clientID;
	private IBuilder builder;
	private MyTextPane text;
	public TextFieldHandler(IBuilder builder2, int clientID, MyTextPane text)
	{
		super();
		this.builder = builder2;
		this.clientID = clientID;
		this.text = text;
	
	}
	@Override
	public void actionPerformed(ActionEvent event) {
		try {
			builder.write(clientID, text.getStyledDocument());
			JOptionPane.showMessageDialog(null, "The commit was succesfull");
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch(IllegalStateException e)
		{
			JOptionPane.showMessageDialog(null, "Conflict:\nyou don't have the newest version.\nSave your changes and force update.");
		}
	}

}
